package com.example.siyun.controller.ordercontroller;

import com.example.siyun.pojo.SyUserOrder;
import com.example.siyun.service.orderservice.CommodityService;
import com.example.siyun.util.JsonResult;
import com.example.siyun.util.PageResult;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * 商品订单列表
 *@author：王浩宇
 *@Date: 2022-10-12
 * */
@RestController
@RequestMapping("/commodity")
@Slf4j
public class CommodityController {

    @Autowired
    private CommodityService commodityService;

    /**
    * 获取全部商品订单
    * @page:页数
    * @limit:条数
    * @return: 商品订单数据
    * */
    @RequestMapping("/get")
    public PageResult<List> get(Integer page, Integer limit){

        PageHelper.startPage(page, limit);
        List<SyUserOrder> all = commodityService.Get();

        PageInfo<SyUserOrder> pageInfo = new PageInfo<>(all);

        PageResult<List> pageResult = new PageResult<>();
        pageResult.setMessage("成功");
        pageResult.setData(pageInfo.getList());
        pageResult.setState(0);
        pageResult.setTotal(pageInfo.getTotal());

        return pageResult;
    }

    /**
    * 商品订单搜索
    * @orderSource:支付方式
    * @orderStatus:订单状态
    * @orderPaymentChannel:订单来源
    * @page:页数
    * @limit:条数
    * @return:商品订单数据
    * */
    @RequestMapping("/select")
    public PageResult<List> select(String orderSource, String orderStatus, String orderPaymentChannel,Integer page, Integer limit){

        PageHelper.startPage(page, limit);
        List<SyUserOrder> all = commodityService.Select(orderSource,orderStatus,orderPaymentChannel);

        PageInfo<SyUserOrder> pageInfo = new PageInfo<>(all);

        PageResult<List> pageResult = new PageResult<>();
        pageResult.setMessage("成功");
        pageResult.setData(pageInfo.getList());
        pageResult.setState(0);
        pageResult.setTotal(pageInfo.getTotal());

        return pageResult;
    }

    /**
    *商品待付款数据
    * @page:页数
    * @limit:条数
    * @return:待付款数据
    * */
    @RequestMapping("/getPayment")
    public PageResult<List> getPayment(Integer page, Integer limit){
        PageHelper.startPage(page, limit);
        List<SyUserOrder> all = commodityService.getPayment();

        PageInfo<SyUserOrder> pageInfo = new PageInfo<>(all);

        PageResult<List> pageResult = new PageResult<>();
        pageResult.setMessage("成功");
        pageResult.setData(pageInfo.getList());
        pageResult.setState(0);
        pageResult.setTotal(pageInfo.getTotal());

        return pageResult;
    }
    /**
     * 商品待付款搜索
     * @orderSource:支付方式
     * @orderStatus:订单状态
     * @orderPaymentChannel:订单来源
     * @page:页数
     * @limit:条数
     * @return:商品待付款数据
     * */
    @RequestMapping("/selectPayment")
    public PageResult<List> selectPayment(String orderSource, String orderStatus, String orderPaymentChannel,Integer page, Integer limit){

        PageHelper.startPage(page, limit);
        List<SyUserOrder> all = commodityService.selectPayment(orderSource,orderStatus,orderPaymentChannel);

        PageInfo<SyUserOrder> pageInfo = new PageInfo<>(all);

        PageResult<List> pageResult = new PageResult<>();
        pageResult.setMessage("成功");
        pageResult.setData(pageInfo.getList());
        pageResult.setState(0);
        pageResult.setTotal(pageInfo.getTotal());

        return pageResult;
    }
    /**
     *商品待发货数据
     * @page:页数
     * @limit:条数
     * @return:待发货数据
     *
     *  */
    @RequestMapping("/getConsignment")
    public PageResult<List> getConsignment(Integer page, Integer limit){
        PageHelper.startPage(page, limit);
        List<SyUserOrder> all = commodityService.getConsignment();

        PageInfo<SyUserOrder> pageInfo = new PageInfo<>(all);

        PageResult<List> pageResult = new PageResult<>();
        pageResult.setMessage("成功");
        pageResult.setData(pageInfo.getList());
        pageResult.setState(0);
        pageResult.setTotal(pageInfo.getTotal());

        return pageResult;
    }
    /**
     * 商品待发货搜索
     * @orderSource:支付方式
     * @orderStatus:订单状态
     * @orderPaymentChannel:订单来源
     * @page:页数
     * @limit:条数
     * @return:商品待发货数据
     * */
    @RequestMapping("/selectConsignment")
    public PageResult<List> selectConsignment(String orderSource, String orderStatus, String orderPaymentChannel,Integer page, Integer limit){

        PageHelper.startPage(page, limit);
        List<SyUserOrder> all = commodityService.selectConsignment(orderSource,orderStatus,orderPaymentChannel);

        PageInfo<SyUserOrder> pageInfo = new PageInfo<>(all);

        PageResult<List> pageResult = new PageResult<>();
        pageResult.setMessage("成功");
        pageResult.setData(pageInfo.getList());
        pageResult.setState(0);
        pageResult.setTotal(pageInfo.getTotal());

        return pageResult;
    }

    /**
     *商品已发货数据
     * @page:页数
     * @limit:条数
     * @return:已发货数据
     *  */
    @RequestMapping("/getShipped")
    public PageResult<List> getShipped(Integer page, Integer limit){
        PageHelper.startPage(page, limit);
        List<SyUserOrder> all = commodityService.getShipped();

        PageInfo<SyUserOrder> pageInfo = new PageInfo<>(all);

        PageResult<List> pageResult = new PageResult<>();
        pageResult.setMessage("成功");
        pageResult.setData(pageInfo.getList());
        pageResult.setState(0);
        pageResult.setTotal(pageInfo.getTotal());

        return pageResult;
    }
    /**
     * 商品已发货搜索
     * @orderSource:支付方式
     * @orderStatus:订单状态
     * @orderPaymentChannel:订单来源
     * @page:页数
     * @limit:条数
     * @return:商品已发货数据
     * */
    @RequestMapping("/selectShipped")
    public PageResult<List> selectShipped(String orderSource, String orderStatus, String orderPaymentChannel,Integer page, Integer limit){

        PageHelper.startPage(page, limit);
        List<SyUserOrder> all = commodityService.selectShipped(orderSource,orderStatus,orderPaymentChannel);

        PageInfo<SyUserOrder> pageInfo = new PageInfo<>(all);

        PageResult<List> pageResult = new PageResult<>();
        pageResult.setMessage("成功");
        pageResult.setData(pageInfo.getList());
        pageResult.setState(0);
        pageResult.setTotal(pageInfo.getTotal());

        return pageResult;
    }
    /**
     *商品已签收数据
     * @page:页数
     * @limit:条数
     * @return:已签收数据
     *  */
    @RequestMapping("/getSigned")
    public PageResult<List> getSigned(Integer page, Integer limit){

        PageHelper.startPage(page, limit);
        List<SyUserOrder> all = commodityService.getSigned();

        PageInfo<SyUserOrder> pageInfo = new PageInfo<>(all);

        PageResult<List> pageResult = new PageResult<>();
        pageResult.setMessage("成功");
        pageResult.setData(pageInfo.getList());
        pageResult.setState(0);
        pageResult.setTotal(pageInfo.getTotal());

        return pageResult;
    }
    /**
     * 商品已签收搜索
     * @orderSource:支付方式
     * @orderStatus:订单状态
     * @orderPaymentChannel:订单来源
     * @page:页数
     * @limit:条数
     * @return:商品已签收数据
     * */
    @RequestMapping("/selectSigned")
    public PageResult<List> selectSigned(String orderSource, String orderStatus, String orderPaymentChannel,Integer page, Integer limit){

        PageHelper.startPage(page, limit);
        List<SyUserOrder> all = commodityService.selectSigned(orderSource,orderStatus,orderPaymentChannel);

        PageInfo<SyUserOrder> pageInfo = new PageInfo<>(all);

        PageResult<List> pageResult = new PageResult<>();
        pageResult.setMessage("成功");
        pageResult.setData(pageInfo.getList());
        pageResult.setState(0);
        pageResult.setTotal(pageInfo.getTotal());

        return pageResult;
    }

    /**
     *商品已取消数据
     * @page:页数
     * @limit:条数
     * @return:已取消数据
     *  */
    @RequestMapping("/getCancel")
    public PageResult<List> getCancel(Integer page, Integer limit){

        PageHelper.startPage(page, limit);
        List<SyUserOrder> all = commodityService.getCancel();

        PageInfo<SyUserOrder> pageInfo = new PageInfo<>(all);

        PageResult<List> pageResult = new PageResult<>();
        pageResult.setMessage("成功");
        pageResult.setData(pageInfo.getList());
        pageResult.setState(0);
        pageResult.setTotal(pageInfo.getTotal());

        return pageResult;
    }

    /**
     * 商品已取消搜索
     * @orderSource:支付方式
     * @orderStatus:订单状态
     * @orderPaymentChannel:订单来源
     * @page:页数
     * @limit:条数
     * @return:商品已取消数据
     * */
    @RequestMapping("/selectCancel")
    public PageResult<List> selectCancel(String orderSource, String orderStatus, String orderPaymentChannel,Integer page, Integer limit){

        PageHelper.startPage(page, limit);
        List<SyUserOrder> all = commodityService.selectCancel(orderSource,orderStatus,orderPaymentChannel);

        PageInfo<SyUserOrder> pageInfo = new PageInfo<>(all);

        PageResult<List> pageResult = new PageResult<>();
        pageResult.setMessage("成功");
        pageResult.setData(pageInfo.getList());
        pageResult.setState(0);
        pageResult.setTotal(pageInfo.getTotal());

        return pageResult;
    }
    /**
     *修改订单状态
     * @id:主键id
     * */
    @RequestMapping("/update")
    public void update(Integer id){
        commodityService.Update(id);
        log.info(id+"修改订单状态为发货");
    }
    /**
     *修改地址
     * @id:主键id
     * @address:地址
     * */
    @RequestMapping("/address")
    public void address(Integer id,String address){
        commodityService.Address(id,address);
        log.info(id+"地址修改为"+address);
    }
    /**
     *商品订单总数
     * @return:商品订单总数
     * */
    @RequestMapping("/number")
    public JsonResult<Integer> number(){
         int a = commodityService.Number();
        JsonResult<Integer> jsonResult = new JsonResult<>();
        jsonResult.setState(a);

        return jsonResult;
    }

    /**
     *商品待付款订单总数
     * @return:商品待付款订单总数
     * */
    @RequestMapping("/numberPayment")
    public JsonResult<Integer> numberPayment(){
        int a = commodityService.numberPayment();
        JsonResult<Integer> jsonResult = new JsonResult<>();
        jsonResult.setState(a);

        return jsonResult;
    }
    /**
     *商品代发货订单总数
     * @return:商品代发货订单总数
     * */
    @RequestMapping("/numberConsignment")
    public JsonResult<Integer> numberConsignment(){
        int a = commodityService.numberConsignment();
        JsonResult<Integer> jsonResult = new JsonResult<>();
        jsonResult.setState(a);

        return jsonResult;
    }
    /**
     *商品已发货订单总数
     * @return:商品已发货订单总数
     * */
    @RequestMapping("/numberShipped")
    public JsonResult<Integer> numberShipped(){
        int a = commodityService.numberShipped();
        JsonResult<Integer> jsonResult = new JsonResult<>();
        jsonResult.setState(a);

        return jsonResult;
    }
    /**
     *商品已完成订单总数
     * @return:商品已完成订单总数
     * */
    @RequestMapping("/numberSigned")
    public JsonResult<Integer> numberSigned(){
        int a = commodityService.numberSigned();
        JsonResult<Integer> jsonResult = new JsonResult<>();
        jsonResult.setState(a);

        return jsonResult;
    }
    /**
     *商品已取消订单总数
     * @return:商品已取消订单总数
     * */
    @RequestMapping("/numberCancel")
    public JsonResult<Integer> numberCancel(){
        int a = commodityService.numberCancel();
        JsonResult<Integer> jsonResult = new JsonResult<>();
        jsonResult.setState(a);

        return jsonResult;
    }
}
